Skip to content

Conversation

@Whathecode
Copy link
Owner

@Whathecode Whathecode commented Dec 14, 2024

Moving an interval can overflow in case the new values of the interval can't be represented by the type.

In the majority of use cases this can probably be ignored, but in those cases where an overflow does occur, an assumption was made that the most likely desirable behavior is to move the interval as far as possible. I.e., 'clamp' the operation to the possible value range.

But, to ensure the caller can still tell overflowed operations apart from fully successful shift operations, the actual amount by which the interval is shifted is included in the return value.

In addition: while writing unit tests for shift, I noticed some errors on EmptyIntervalUnion operations, which are now fixed.

Some things left to consider:

  • Add a test to verify the assumption that "all negative values of TSize have a positive counterpart". And, is this a fair limitation for potential types of TSize? Found a workaround/no longer a requirement.
  • Deal with precision issues at large values. This can probably lead to intervals "collapsing" to single values, and failing on initialization with two exclusive bounds. If dealt with, maybe increase possible range of float and double again to allow loss of precision. **Postponed: Likely error when shifting intervals of types which have loss of precision #64 **
  • Improve shift overflow tests so they are less sensitive to precision issues. Maybe add extra test input if relevant?
  • Add test + fix to prevent unsafeShift infinite loops on "infinity" values.
  • Should the actual resulting shifted value in case of overflows be signed? Is it currently consistent? Should be signed now, but maybe needs more tests.
  • Shift union pairs (TODO item)

@Whathecode Whathecode force-pushed the shift branch 8 times, most recently from b0546ad to bd3faa4 Compare December 17, 2024 20:50
@Whathecode Whathecode force-pushed the shift branch 3 times, most recently from 34d8710 to 67e4285 Compare December 22, 2024 15:33
@Whathecode Whathecode force-pushed the develop branch 2 times, most recently from 9c169ca to 9f80b3f Compare December 23, 2024 09:17
@Whathecode Whathecode force-pushed the shift branch 5 times, most recently from 29f4912 to e5c5219 Compare December 30, 2024 16:23
This allows implementations which lead to less loss of precision.
@Whathecode Whathecode force-pushed the shift branch 2 times, most recently from 68337b1 to 93522e6 Compare January 3, 2025 18:56
@Whathecode Whathecode force-pushed the shift branch 5 times, most recently from 221658f to 795263f Compare January 4, 2025 11:25
And, fix infinity interval sizes for float/double intervals by reducing the min/max of interval type operations, which in turn allows reintroducing infinity as min/max values for the basic type operations.
Since `IntervalTypeOperations` has changed, this is now a breaking API version.
@Whathecode Whathecode marked this pull request as ready for review January 4, 2025 16:16
@Whathecode Whathecode merged commit 92c1413 into develop Jan 4, 2025
3 checks passed
@Whathecode Whathecode deleted the shift branch January 6, 2025 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants